package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺操作接口")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result setUpShop(@PathVariable Integer status ){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("shop-Status",status);
        log.info("设置店铺为：{}",status==1? "营业中":"打样中");
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getShop(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
       Integer shopStatus = (Integer) valueOperations.get("shop-Status");
       return Result.success(shopStatus);
    }
}
